<?php

namespace app\admin\controller;

use think\Controller;
use think\Request;

class Base extends Controller
{
    public $admin_id;
    public $admin_info;


    public function __construct(Request $request = null)
    {
        parent::__construct($request);
        $this->admin_id = session('admin_id');
        $this->admin_info = session('admin_info');
        if (!$this->admin_id) {
            // echo json(['code'=>1001,'msg'=>'auth error']);
            // die;
//            $this->lyerror('auth error');
            $this->redirect('/admin/auth/login');

        }

    }


    /**
     * 为数组设默认字段 防止TP报错
     * @param $array
     * @param $default
     * @return mixed
     */
    public function set_array_default($array, $default = '无')
    {

        foreach ($array as $index => $re) {
            if (!$re) {
                $array[$index] = $default;
            }
        }
        return $array;

    }


       //删除多余空格
    public function _trim($data_array)
    {
        foreach ($data_array as $index => $re) {
            if(!is_array($re)){
                $data_array[$index] = trim($re);
            }

        }
        return $data_array;
    }


}
